#include "cc_fs.h"
#include "Preferences.h"

static Preferences eeprom_fs;
int cc_fs_init()
{
  if (!eeprom_fs.begin("eeprom_fs"))
  {
    cc_log_e("eeprom fs init failed\r\n");
    return -1;
  }
  cc_log("sizeof fs:%d\r\n", eeprom_fs.freeEntries());

  return 1;
}
CC_INIT_BOARD_REGISTER(cc_fs_init);

String cc_fs_get_string(const char* key)
{
  return eeprom_fs.getString(key);
}

int cc_fs_set_string(const char* key, char* data)
{
  return eeprom_fs.putString(key, data);
}

int cc_fs_get_bool(const char* key)
{
  return eeprom_fs.getBool(key);
}

int cc_fs_set_bool(const char* key, int data)
{
  return eeprom_fs.putBool(key, data);
}

int cc_fs_get_int(const char* key)
{
  return eeprom_fs.getInt(key);
}

int cc_fs_set_int(const char* key, int data)
{
  return eeprom_fs.putInt(key, data);
}

double cc_fs_get_double(const char* key)
{
  return eeprom_fs.getDouble(key);
}

int cc_fs_set_double(const char* key, double data)
{
  return eeprom_fs.putDouble(key, data);
}

float cc_fs_get_float(const char* key)
{
  return eeprom_fs.getFloat(key);
}

int cc_fs_set_float(const char* key, float data)
{
  return eeprom_fs.putFloat(key, data);
}

int8_t cc_fs_set_char(const char* key, int8_t data)
{
  return eeprom_fs.putChar(key, data);
}

char cc_fs_get_char(const char* key)
{
  return eeprom_fs.getChar(key);
}

int cc_fs_set_uchar(const char* key, uint8_t data)
{
  return eeprom_fs.putUChar(key, data);
}

uint8_t cc_fs_get_uchar(const char* key)
{
  return eeprom_fs.getUChar(key);
}

int cc_fs_set_uint(const char* key, uint32_t data)
{
  return eeprom_fs.putUInt(key, data);
}

uint32_t cc_fs_get_uint(const char* key)
{
  return eeprom_fs.getUInt(key);
}

int cc_fs_set_bytes(const char* key, void* data, uint32_t len)
{
  return eeprom_fs.putBytes(key, data, len);
}

int cc_fs_get_bytes(const char* key, void* data, uint32_t len)
{
  return eeprom_fs.getBytes(key, data, len);
}

int cc_fs_remove_key(const char* key)
{
  return eeprom_fs.remove(key);
}

int cc_fs_clear()
{
  return eeprom_fs.clear();
}

uint32_t cc_fs_get_free_size()
{
  return eeprom_fs.freeEntries();
}